﻿
using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using BE;

namespace DA
{
    public class daReporteGuardia
    {
        public static DataTable Obtener(beReporteGuardia oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_ConsultarReporteGuardia");
            sqlClient.AddInParameter(dbCmd, "@IDReporteGuardia", DbType.Int32, oBE.IDReporteGuardia);
            sqlClient.AddInParameter(dbCmd, "@IDPozo", DbType.Int32);
            sqlClient.AddInParameter(dbCmd, "@Fecha", DbType.DateTime );
            sqlClient.AddInParameter(dbCmd, "@Turno", DbType.Int32);
            sqlClient.AddInParameter(dbCmd, "@Sistema", DbType.String);
            sqlClient.AddInParameter(dbCmd, "@Diametro", DbType.String);
            sqlClient.AddInParameter(dbCmd, "@Desde", DbType.Int32);
            sqlClient.AddInParameter(dbCmd, "@Hasta", DbType.Int32);
            sqlClient.AddInParameter(dbCmd, "@Observaciones", DbType.String);
            sqlClient.AddInParameter(dbCmd, "@Desactivado", DbType.Boolean);
            return sqlClient.ExecuteDataSet(dbCmd).Tables[0];
        }

        public static Int32  Registrar(beReporteGuardia oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_RegistrarReporteGuardia");
            sqlClient.AddInParameter(dbCmd, "@IDReporteGuardia", DbType.Int32, oBE.IDReporteGuardia);
            sqlClient.AddInParameter(dbCmd, "@IDPozo", DbType.Int32, oBE.IDPozo);
            sqlClient.AddInParameter(dbCmd, "@Fecha", DbType.DateTime, oBE.Fecha);
            sqlClient.AddInParameter(dbCmd, "@Turno", DbType.Int32, oBE.Turno);
            sqlClient.AddInParameter(dbCmd, "@Sistema", DbType.String, oBE.Sistema);
            sqlClient.AddInParameter(dbCmd, "@Diametro", DbType.String, oBE.Diametro);
            sqlClient.AddInParameter(dbCmd, "@Desde", DbType.Single, oBE.Desde);
            sqlClient.AddInParameter(dbCmd, "@Hasta", DbType.Single, oBE.Hasta);
            sqlClient.AddInParameter(dbCmd, "@Observaciones", DbType.String, oBE.Observaciones);
            sqlClient.AddInParameter(dbCmd, "@Desactivado", DbType.Boolean, oBE.Desactivado);
            sqlClient.AddOutParameter(dbCmd, "@IDOut", DbType.Int64, 1024  )    ;
            int intRespuesta = Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
            oBE.IDReporteGuardia = Convert.ToInt64( sqlClient.GetParameterValue(dbCmd, "@IDOut")) ;
            return Convert.ToInt32(intRespuesta );
        }

        public static Int32 Eliminar(beReporteGuardia  oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_AnularReporteGuardia");
            sqlClient.AddInParameter(dbCmd, "@IDReporteGuardia", DbType.Int32, oBE.IDReporteGuardia);

            return Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
            //sqlClient.ExecuteNonQuery(dbCmd);
        }
        public static Int32 Modificar(beReporteGuardia oBE)
        {
            SqlDatabase sqlClient = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlClient.GetStoredProcCommand("sp_ModificarReporteGuardia");
            sqlClient.AddInParameter(dbCmd, "@IDReporteGuardia", DbType.Int32, oBE.IDReporteGuardia);
            sqlClient.AddInParameter(dbCmd, "@IDPozo", DbType.Int32, oBE.IDPozo);
            sqlClient.AddInParameter(dbCmd, "@Fecha", DbType.DateTime, oBE.Fecha);
            sqlClient.AddInParameter(dbCmd, "@Turno", DbType.Int32, oBE.Turno);
            sqlClient.AddInParameter(dbCmd, "@Sistema", DbType.String, oBE.Sistema);
            sqlClient.AddInParameter(dbCmd, "@Diametro", DbType.String, oBE.Diametro);
            sqlClient.AddInParameter(dbCmd, "@Desde", DbType.Single, oBE.Desde);
            sqlClient.AddInParameter(dbCmd, "@Hasta", DbType.Single, oBE.Hasta);
            sqlClient.AddInParameter(dbCmd, "@Observaciones", DbType.String, oBE.Observaciones);
            sqlClient.AddInParameter(dbCmd, "@Desactivado", DbType.Boolean, oBE.Desactivado);
            return Convert.ToInt32(sqlClient.ExecuteScalar(dbCmd));
        }

    }
}
